package com.fjw.mapper;

import com.fjw.pojo.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {

    @Insert("INSERT INTO `order` (user_id, tea_ids, total_price, create_time, status) " +
            "VALUES (#{userId}, #{teaIds}, #{totalPrice}, #{createTime}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Order order);

    @Select("SELECT * FROM `order` WHERE id = #{id}")
    Order findById(Integer id);

    @Select("SELECT * FROM `order` WHERE user_id = #{userId} ORDER BY create_time DESC")
    List<Order> findByUserId(Integer userId);

    @Select("SELECT * FROM `order` ORDER BY create_time DESC")
    List<Order> findAll();

    @Update("UPDATE `order` SET status = #{status} WHERE id = #{id}")
    int updateStatus(@Param("id") Integer id, @Param("status") Integer status);

    @Delete("DELETE FROM `order` WHERE id = #{id}")
    int deleteById(Integer id);
}